using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;
using System.Data;

namespace HeThongDAO
{
    public class TacGiaDAO
    {
        public static DataTable SelectAll()
        {
            string sql = "SELECT * FROM TAC_GIA";
            return Config.AccessHelper.ExecuteQuery(sql);
        }

        public static DataTable DocSchema()
        {
            return Config.AccessHelper.Doc_Cau_Truc("TAC_GIA");
        }

        public static bool ThemTacGia(TacGiaDTO tgDTO)
        {
            try
            {
                string sql = "INSERT INTO TAC_GIA(TenTacGia) ";
                sql += "VALUES('" + tgDTO.TenTacGia.ToString() + "')";

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool CapNhatTacGia(TacGiaDTO tgDTO)
        {
            try
            {
                string sql = "UPDATE TAC_GIA SET ";
                sql += "TenTacGia = '" + tgDTO.TenTacGia.ToString() + "'";
                sql += " WHERE MaTacGia = " + tgDTO.MaTacGia;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool XoaTacGia(TacGiaDTO tgDTO)
        {
            try
            {
                string sql = "DELETE FROM TAC_GIA ";
                sql += "WHERE MaTacGia = " + tgDTO.MaTacGia;

                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
